﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;

public partial class Compare_ListProduct : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Text.StringBuilder output = new System.Text.StringBuilder();
        ArrayList listId = new ArrayList();
        ArrayList ListProduct = new ArrayList();


        ArrayList ListSeri = new ArrayList();
        ArrayList ListTenHang = new ArrayList();
        ArrayList ListPicUrl = new ArrayList();
        ArrayList ListGiaThamKhao = new ArrayList();
        ArrayList ListGiaChietKhau = new ArrayList();
        ArrayList ListNoiSX = new ArrayList();
        ArrayList ListThongSo = new ArrayList();
        
        // Get list Id product compare from cookie
        if (Request.Cookies["shopping_compare"] != null)
        {
            HttpCookie aCookie = Request.Cookies["shopping_compare"];
            //output.Append("Cookie name = " + Server.HtmlEncode(aCookie.Value) + "<br />");
            string[] list = Server.HtmlEncode(aCookie.Value).Split(',');

            if (list.Length > 0)
            {
                for (int i = 0; i < list.Length; i++)
                {
                    if (list[i].Length > 0 && list[i] != null && list[i] != "")
                    {
                        int lastChar = list[i].IndexOf("|");
                        string id = list[i].Substring(0, lastChar);
                        listId.Add(id);
                        output.Append(id);
                    }
                }

            }
        }

        // Get product properties from db
        if (listId.Count > 0)
        {

            for (int i = 0; i < listId.Count; i++)
            {

                CommonDAO cm = new CommonDAO();
                string squery = "select Seri, TenHang, PicUrl, GiaBanThamKhao, GiaBanCoChietKhau, ThongSo, n.NoiSX from SanPham s inner join SanPham_NoiSX n on s.NoiSXID=n.id where s.id =" + listId[i];
                DataTable dt = cm.queryForTable(squery, "t");
                foreach (DataRow dtrow in dt.Rows)
                {
                    ListSeri.Add(dtrow[0].ToString());
                    ListTenHang.Add(dtrow[1]);
                    ListPicUrl.Add(dtrow[2].ToString().Replace("../", string.Empty));
                    ListGiaThamKhao.Add(dtrow[3]);
                    ListGiaChietKhau.Add(dtrow[4]);
                    ListThongSo.Add(dtrow[5]);
                    ListNoiSX.Add(dtrow[6]);
                }
            }
        }

        if (!Page.IsPostBack)
        {
            
            rptSeri.DataSource = ListSeri;
            rptSeri.DataBind();
            rptTenHang.DataSource = ListTenHang;
            rptTenHang.DataBind();
            rptPicUrl.DataSource = ListPicUrl;
            rptPicUrl.DataBind();
            rptGiaThamKhao.DataSource = ListGiaThamKhao;
            rptGiaThamKhao.DataBind();
            rptGiaChietKhau.DataSource = ListGiaChietKhau;
            rptGiaChietKhau.DataBind();
            rptNoiSX.DataSource = ListNoiSX;
            rptNoiSX.DataBind();
            rptThongSo.DataSource = ListThongSo;
            rptThongSo.DataBind();
            
        }
    }
}
